<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: 肖林
  Date: 2018/4/10
  Time: 19:27
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>增加一个用户</title>
</head>
<body>

<form method="post">
    username:<input type="text" name="username" value="username">
    </br>
    password:<input type="password" name="password" value="password">
    </br>
    <input type="submit" value="添加">
    <a href="lab01.jsp"><input type="button" value="返回"></a>

    <%
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        if((username != null)&&(password != null)) {
            Connection connection = null;
            Statement statement = null;

            String sql = "INSERT INTO t_user(username,password) " +
                    "VALUES ('" + username + "','" + password + "')";
            Class.forName("com.mysql.jdbc.Driver");
            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/javaweb_2018?serverTimezone=UTC",
                    "root",
                    "195122"
            );
            statement = connection.createStatement();
            statement.execute(sql);

            connection.close();
            statement.close();
        }
    %>

</form>
</body>
</html>
